package com.evil.application.pojo.dto.form.rule;

import com.alibaba.fastjson.JSON;
import com.evil.application.pojo.entity.ApplicationFormSnRule;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;

/**
 * 表单规则 返回实体
 *
 * @author liyang
 * @date 2022-08-08 00:00
 */
@Data
@NoArgsConstructor
public class SnRuleRespDTO {

    /**
     * 规则id
     */
    private Long applicationFormRuleId;

    /**
     * 规则类型(0:自增值, 1: 提交日期, 2:固定字符, 3:表单内字段)
     */
    @NotNull(message = "规则类型不能为空")
    private Integer ruleType;

    /**
     * 编号生成规则
     */
    @Valid
    @NotNull(message = "编号生成规则不能为空")
    private SnRuleConfigDTO snRuleConfig;

    public SnRuleRespDTO(ApplicationFormSnRule applicationFormSnRule) {
        this.applicationFormRuleId = applicationFormSnRule.getFormRuleId();
        this.ruleType = applicationFormSnRule.getRuleType();
        this.snRuleConfig = JSON.parseObject(applicationFormSnRule.getSnRuleConfig(), SnRuleConfigDTO.class);
    }
}
